<template>
	<view>
		<view class="content">
			<u-navbar :fixed="false" :title="titleName" :autoBack="false" :safeAreaInsetTop="true">
				<view slot="left" class="x-f">
					<u-icon name="arrow-left" color="#fff" size="20" @click="goBack"></u-icon>

					<u-icon name="close" color="#fff" size="20" style="margin-left: 20px;"
						@click="goBack('close')"></u-icon>
				</view>
				<view slot="right">
					<m-bubble type="list" :selectData="formMenus" position="right" topOpsotion="right" bgcRgba="#fff"
						color="#333" @selectFun="TapPopup">
						<u-icon name="more-dot-fill" color="#fff" class="moremenu"></u-icon>
					</m-bubble>
				</view>
			</u-navbar>

			<view class="content_main">
				<view style="background-color: #fff;margin-bottom: 16rpx;">
					<!-- 顶部卡片 -->
					<view style="padding: 20rpx;">
						<view class="content_main_CardBox TopCard x-f">
							<view class="CardInfo">
								<m-field labelFontSize="36rpx" labelColor="#fff" labelWeight="600" paddings="10rpx"
									@click="$utils.TextCopyFun(mainTitle)" :borderBottom="false">
									<template #custom-label>
										<view class="x-f">
											<text>{{mainTitle}}</text>

											<uni-icons v-if="mainTitle" fontFamily="CustomFontPlatform" color="#f1f1f1"
												style="margin-left: 4rpx;"
												size="16">{{$utils.toUniCode('&#xe862;')}}</uni-icons>
										</view>
									</template>
								</m-field>


								<!-- <m-field labelFontSize="28rpx" labelColor="#fff" labelWeight="600" paddings="10rpx"
								@click="$utils.TextCopyFun('套票-XSDD-20240612-00011')" :borderBottom="false"
								label="套票-XSDD-20240612-00011"></m-field> -->

								<m-field style="margin-top: 18rpx;" labelFontSize="24rpx" labelColor="#fff"
									v-for="item in mainForm" paddings="0rpx" :borderBottom="false"
									:label="item.name+':'" :value="item.value" valueColor="#fff" valueFontSize="24rpx">
								</m-field>

							</view>

							<view class="CardTag">
								<!-- <view class="x-c myTag" v-for="tag in tagForm">
								<text>{{tag.text}}</text>
							</view> -->
								<u-tag :text="tag.text" v-for="tag in tagForm" style="margin-left: 10rpx;" size="large"
									plain plainFill shape="circle" :type="tag.type"></u-tag>


							</view>
						</view>
					</view>

					<!-- 表单数据 -->
					<u-cell-group :border="false">
						<view v-for="(childForm,index) in childFormList">
							<u-cell :titleStyle="{'fontSize': '26rpx',color:'#626262'}" :border="false" title="合计:">
								<view slot="value">
									<text
										style="color: #2e2e2e;font-size: 26rpx;">{{showChildFormTableDataLen()}}</text>
								</view>
							</u-cell>
							<u-cell :titleStyle="{'fontSize': '26rpx',color:'#626262'}" :border="false"
								v-if="!totalFunc.isHidden" :title="totalFunc.colDesc"
								v-for="totalFunc in childForm.totalFunctions">
								<view slot="value">
									<text style="color: #2e2e2e;font-size: 26rpx;">{{totalFunc.summaryData}}</text>
								</view>
							</u-cell>
						</view>
					</u-cell-group>
				</view>

				<!-- 吸顶Tab栏 -->
				<u-sticky style="background-color: #fff;top: 0 !important;box-shadow: 0 8px 11px -19px;">
					<u-tabs keyName="title" :list="TabList" :is-scroll="false" :current="tabCurrent"
						@change="clickTabItem" activeStyle="color: #51d0d0;" lineWidth="60" lineColor="#51d0d0"
						:scrollable="false">
						<template #TabText="{element,index}">
							<view style="font-size: 28rpx;">{{element.title}}</view>
						</template>
					</u-tabs>
				</u-sticky>

				<view class="MainBox">
					<!-- 商品信息 -->
					<view v-if="tabCurrent == 0">

						<view class="Main_CardListBox" v-for="(childForm,index) in childFormList">
							<view class="content_main_CardBox" v-for="(item,idx) in childForm.tableData"
								style="margin-bottom: 10rpx;">
								<view class="FiledBox">
									<view v-if="childForm.hasOwnProperty('titleCol')">

										<text class="FiledBox_label_f28" v-if="childForm.titleCol.colType!=2">
											<text class="van-badge">{{ idx+1 }}</text>
											{{ item[childForm.titleCol.colName]}}</text>
										<text class="FiledBox_label_f28" v-else="childForm.titleCol.colType==2"><text
												class="van-badge">{{ idx+1 }}</text>
											{{ showActualValue(item[childForm.titleCol.colName],childForm.titleCol ) }}</text>

									</view>

									<view v-else>
										<text class="FiledBox_label_f18"><text
												class="van-badge">{{ idx+1 }}</text></text>
									</view>

								</view>
								<!-- <view class="content_main_CardBox_RightTop y-end"
									style="position: absolute;right: 10rpx;top: 20rpx;">
									<view class="FiledBox">
										<text class="FiledBox_label_f28">500.00</text>
									</view>
									<view class="FiledBox">
										<text class="FiledBox_label_f28">X1</text>
									</view>
								</view> -->
								<view class="FiledBox x-f" v-for="col in childApproveShowFun(childForm.columns)"
									v-if="!col.isHidden && !col.isTitle">
									<text class="FiledBox_label_f24 FiledBox_grifola">{{ col.colDesc }}:</text>

									<!-- 上传框 -->
									<!-- <view v-if="col.colType==5" class="x-f"
										style="flex: 1;overflow: hidden;background-color: pink;">
										<view class="x-f" v-if="btnShowCallBack(item,col)">

											<u--image :showLoading="true" :src="FileTypeByName(item,col)" width="30px"
												height="30px"></u--image>

											<u-tag text="查看附件" @click="FilePathView(item,col)" type="primary" plain
												plainFill size="mini" style="margin-left: 10px;"></u-tag>

										</view>

									</view> -->
									<view v-if="col.colType==5" style="width:100%">

										<cl-upload v-model="item[col.colName + '_show']" :uploadKey="col.colName"
											:add="false" :remove="false" :imageFormData="{compress:false}"
											:listStyle="{columns: BoxInfoCallBack.num,height:BoxInfoCallBack.height+'rpx',padding:'6px',columnGap:'10px',rowGap:'10px'}"
											cloudType="other"></cl-upload>
									</view>


									<!-- 下拉框 -->
									<text class="FiledBox_value FiledBox_value_f24 FiledBox_grifola"
										v-else-if="col.colType==2">{{showActualValue(item[col.colName],col) }}</text>

									<!-- 文本框 -->
									<view v-else style="flex: 1;overflow: hidden;">

										<text
											class="FiledBox_value FiledBox_value_f24 FiledBox_grifola">{{item[col.colName]}}</text>


									</view>
								</view>

							</view>
						</view>

					</view>

					<!-- 单据信息 -->
					<!-- <view class="Main_CardListBox" v-if="tabCurrent == 1">
					<u-cell-group :border="false" style="padding: 10rpx;background-color: #fff;">
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="预售款余额"
							value="35732.00"></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="应收款余额"
							value="-35732.00"></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="true" title="需要开票" value="否"></u-cell>

						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="业务员" value=""></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="true" title="部门" value=""></u-cell>

						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="送货地址" value=""></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="合同号" value=""></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="true" title="项目" value=""></u-cell>

						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="单据备注" value=""></u-cell>
					</u-cell-group>
				</view> -->


					<!-- 联查信息，关联单据 -->
					<view class="Main_CardListBox" v-if="tabCurrent == TabList.length-1">
						<u-cell-group :border="false" style="padding: 10rpx;background-color: #fff;">
							<u-cell v-for="(item,index) in objDetailModelList" :key="index"
								@click="openDetailPage(item)" :titleStyle="{'fontSize': '26rpx',color:'#626262'}"
								:border="false" :title="item.Title">
								<view slot="value">
									<text style="font-size: 26rpx;"
										:style="{color:item.APPUrl ? '#4499ec' : '#2e2e2e' }">{{item.BillNO}}</text>
								</view>
							</u-cell>
						</u-cell-group>
					</view>
				</view>

			</view>


			<view class="content_bottom1 x-ec " :style="$utils.disposeSafeBottomFun()">
				<!-- content_bottom_primary_Btn -->

				<!-- 审批流 -->
				<button class="CommonBtnSize workBtn" plain style="margin-left: 10px;" :disabled="!enabledSubmitBtn"
					v-if="
					approvalConfig.isEnableApproval && (!formData.Status || formData.Status==3) && !formData.Approve &&
					workList.filter(function(item){ return item.name=='发起审批' }).length==0" @click="startApprove">
					<text>发起审批</text>
				</button>

				<button class="CommonBtnSize workBtn" plain style="margin-left: 10px;" :disabled="!enabledSubmitBtn"
					@click="formApprove"
					v-if="approvalConfig.isEnableApproval && formData.Status == 1 && isCurApproval">
					<text>审批单据</text>
				</button>

				<button class="CommonBtnSize workBtn" plain style="margin-left: 10px;" :disabled="!enabledSubmitBtn"
					@click="cancelApprove" v-if="approvalConfig.isEnableApproval && formData.Status == 1">
					<text>撤销审批</text>
				</button>


				<!-- <button class="CommonBtnSize workBtn" plain v-for="btn in workList" style="margin-left: 10px;"
					v-if="btn_showCondition(2,btn)" @click="selfWorkHandler(btn)">
					{{ btn.name }}
				</button> -->

				<!-- 当业务按钮存在一项时 -->
				<view v-if="MoreSheetList.length == 1 && btnAllowShowFun(MoreSheetList[0]['name'])">
					<button class="CommonBtnSize workBtn x-c" :class="buttonClasses" :style="buttonStyles"
						:disabled="!enabledSubmitBtn" plain v-for="btn in MoreSheetList" style="margin-left: 10px;"
						@click="selfWorkHandler(btn)">
						{{ btn.name }}
					</button>
				</view>
				<!-- 当存在多项业务按钮时 -->
				<view v-else-if="MoreSheetList.length > 1">
					<u-button :disabled="!enabledSubmitBtn" class="CommonBtnSize content_bottom_primary_plainBtn"
						@click="openMoreSheet" text="更多"></u-button>
				</view>


				<button v-if="btnAllowShowFun('编辑')" :disabled="!enabledSubmitBtn"
					class="CommonBtnSize content_bottom_primary_Btn" style="margin-left: 10px;"
					@click="toEdit">编辑</button>
			</view>


		</view>

		<m-loading text="正在渲染" v-model="showMLoading" :showClose="false"
			maskBackgroundColor="rgba(0,0,0,0.3)"></m-loading>

		<u-action-sheet :actions="MoreSheetList" safeAreaInsetBottom :closeOnClickOverlay="true" cancelText="取消"
			:closeOnClickAction="true" @select="selfWorkHandler" :show="showMoreSheet"
			@close="closeSheetBtn"></u-action-sheet>

	</view>
</template>

<script>
	// import requestQueue from '@/common/http/requestQueue.js';
	// var requestManager = requestQueue;
	import layerFun from '@/common/comFun/layerFun.js';
	var layer = layerFun;

	import ApprovalFuns from '@/common/comFun/ApprovalFun.js';

	var ApprovalFun = ApprovalFuns;


	import {
		taskManager
	} from '@/common/http/taskQueue.js';
	const open = uni.requireNativePlugin("Html5App-openFile");
	// var vm;
	export default {
		data() {
			return {
				showMLoading: false,
				btnStyle: {
					width: 79,
					height: 40
				},
				titleName: '详情',
				MenuDetail: {},
				detailName: '',
				physicalTableName: '',
				keyName: '',
				keyValue: '',
				mainTitle: '',
				mainForm: [],
				tagForm: [],
				formData: {},
				formMenus: [{
						name: '查阅审批流',
						value: '',
						icon: 'list-dot'
					},
					{
						name: '单据设置',
						value: '',
						icon: 'order'
					},
					{
						name: '刷新',
						value: '',
						icon: 'reload'
					},
				],

				pageWhere: [0, 0, 0], // 记录切换tab后，前一项所在位置
				tabCurrent: null, // 选中tab项索引
				TabList: [],
				childFormList: [],
				changeDataSource: [],
				workList: [],
				objDetailModelList: [],
				lastCallCom: 0, // 节流
				showMoreSheet: false, // 更多按钮--操作菜单
				MoreSheetList: [],
				approvalConfig: {
					isEnableApproval: false,
				},
				isCurApproval: false, // 判断是否为当前审批人
				ApprovalSort: null,
				globalData: {},
				isShowComApproval: false,
				enabledSubmitBtn: false, // 按钮点击限制

				approveObj: {},
				ApprovalID: null, // 审批ID

				APPRoleCol: [], // 主表单隐藏字段
				APPRoleColChildList: [], // 子表权限隐藏字段


				BoxInfoCallBack: {
					num: 3,
					height: 100
				}
			};
		},
		/* created() {
			var that = this;
			let vm = this;
			const job = taskManager.createJob('demoTask');

			taskManager.addAction(job, {
				type: 'function',
				async: false,
				execution: () => {
					//详情页对象名称，具体id值
					let menuDetailObj = this.$utils.deepClone(this.$store.state.MenuDetail);
					that.MenuDetail = menuDetailObj;
					that.detailName = menuDetailObj.detailName;
					that.keyName = menuDetailObj.keyName;
					that.keyValue = menuDetailObj.keyValue;
					that.titleName = menuDetailObj.detailTitle.replace('列表', '') + '详情';
					that.mainTitle = menuDetailObj.dataInfo.titleColName;
					that.mainForm = menuDetailObj.dataInfo.showColumnsInfo;
					that.tagForm = menuDetailObj.dataInfo.tagColumnsInfo;
				}
			})

			taskManager.addAction(job, {
				type: 'function',
				async: true,
				execution: () => {
					return new Promise(async (resolve, reject) => {

						await that.initConfig(that.detailName);

						function aa() {
							return new Promise((res, rej) => {
								console.log("aaaaaa");
								setTimeout(() => {
									console.log(123);
									res()
								}, 3000)

							})
						}
						await aa();

						console.log(333);
						console.log(444);

						resolve();
					})
				}
			})

			taskManager.addAction(job, {
				type: 'function',
				async: true,
				execution: () => {
					console.log(3);
				}
			})

			taskManager.addJob(job)


		}, */
		created() {
			var that = this;
			let vm = this;

			//详情页对象名称，具体id值
			let menuDetailObj = this.$utils.deepClone(this.$store.state.MenuDetail);
			that.MenuDetail = menuDetailObj;
			that.detailName = menuDetailObj.detailName;
			that.keyName = menuDetailObj.keyName;
			that.keyValue = menuDetailObj.keyValue;
			that.titleName = menuDetailObj.detailTitle.replace('列表', '') + '详情';
			that.mainTitle = menuDetailObj.dataInfo.titleColName;
			that.mainForm = menuDetailObj.dataInfo.showColumnsInfo;
			that.tagForm = menuDetailObj.dataInfo.tagColumnsInfo;

			that.initConfig(that.detailName);

		},
		onLoad() {},
		computed: {
			buttonClasses() {
				return {
					'small-font': this.btnStyle.width < 80,
					'disabled': !this.enabledSubmitBtn
				}
			},
			buttonStyles() {
				return {
					height: this.btnStyle.height ? `${this.btnStyle.height}px` : 'auto',
					'line-height': '20px'
				}
			}
		},
		mounted() {
			let that = this;
			let vm = this;
			// 组件卸载时清理任务
			// this.$once('hook:beforeDestroy', () => {
			// 	taskManager.stopPolling()
			// })
			setTimeout(() => {
				that.tabCurrent = 0;
				let getSystemInfoSync = uni.getSystemInfoSync();
				let backData = that.$utils.calculateAdaptiveLayout(getSystemInfoSync.screenWidth, 20)
				that.BoxInfoCallBack = backData;
			}, 300);

			// 组件中监听队列完成
			this.$onQueueEvent('queueEmpty', () => {
				// 当所有事件加载完成后：
				// 开放按钮点击权限

				that.$utils.hideLoading();
				that.showMLoading = false;
				that.enabledSubmitBtn = true; // 解开按钮限制
			});
			this.$onQueueEvent('requestStart', (ret) => {});
			this.$onQueueEvent('requestSuccess', (ret) => {});
			this.$onQueueEvent('requestRetry', (ret) => {});
			this.$onQueueEvent('requestFail', (ret) => {
				// 当所有事件加载完成后：
				// 开放按钮点击权限
				if (ret.detail.status == 500) {
					layer.confirm("接口请求异常，请点击刷新或退出", {
						title: "提示",
						confirmText: "刷新",
						cancelText: "退出",
					}, function(ret) {
						if (ret.action == 'confirm') {
							that.initConfig(that.detailName);
						} else if (ret.action == 'cancel') {
							that.goBack();
						}

					});
				} else {
					layer.confirm(JSON.stringify(ret), {
						title: "请求失败，点击刷新或退出",
						confirmText: "刷新",
						cancelText: "退出",
					}, function(ret) {
						if (ret.action == 'confirm') {
							that.initConfig(that.detailName);
						} else if (ret.action == 'cancel') {
							that.goBack();
						}

					});
				}

			});

			// 监听刷新
			uni.$on('refreshToIndex', () => {
				that.refreshPage();
			});

			// 监听list回写的数据
			uni.$on('newListData', (ret) => {
				if (!that.$utils.isEmpty(ret)) {
					that.tagForm = ret.data;
				}
			});

			that.$nextTick(() => {

				uni.createSelectorQuery().select('.CommonBtnSize').boundingClientRect(rect => {
					// that.btnStyle = rect
					Object.assign(that.btnStyle, rect)
				}).exec();
			})

		},
		onUnload() {
			uni.$off('refreshToIndex');
			uni.$off('newListData');
			// taskManager.stopPolling()
		},
		methods: {
			btnAllowShowFun(str) { // 判断当前按钮是否允许显示
				const filterUnPermissionConfig = this.$store.state.appConfigInfo.filterUnPermissionConfig;
				// 检查是否存在任何项的 FunName 与传入的字符串相匹配
				const isFunctionDenied = filterUnPermissionConfig.some(item => item.FunName === str);
				return !isFunctionDenied;
			},
			childApproveShowFun(data) { // 子表数据映射
				let vm = this;
				let that = this;
				try {
					if (!this.$utils.isEmpty(data)) {
						const appRoleColChildMap = that.APPRoleColChildList;
						data.forEach(item => {
							const colName = item.colName; // 缓存colName，减少访问次数
							const typeInfo = appRoleColChildMap.get(colName);
							if (typeInfo) {
								const isViewRole = typeInfo.IsViewRole;
								const isEditRole = typeInfo.IsEditRole;
								item.isHidden = !isViewRole;
								item.isReadOnly = !isViewRole && !isEditRole;
							}
						});
					};

				} catch (error) {
					//TODO handle the exception
				}

				return data || [];
			},
			goBack(str = 'back') {

				if (str == 'close') {
					let routes = getCurrentPages(); //当前页面栈

					let routePageCurrent = this.$store.state.appConfigInfo.routePageCurrent;

					let backNum = routes.length - routePageCurrent;
					uni.navigateBack({
						delta: backNum
					})

				} else {
					uni.navigateBack();
				}

			},
			refreshPage() { // 刷新当前页、列表、详情
				let vm = this;
				vm.initConfig(vm.detailName);
				uni.$emit('refreshToApprove'); // 刷新审批待办

				uni.$emit('FormInitToRefresh', { // 触发列表、详情
					keyID: vm.formData[vm.keyName]
				});
			},
			post(sql, param, callBack) {
				let vm = this;
				param["sql"] = sql;

				const userInfo = vm.Request.getUserInfo();
				if (!this.$utils.isEmpty(userInfo)) {

					if (!param.hasOwnProperty("P_UserID")) {
						param.P_UserID = userInfo.UserID;
					}
					if (!param.hasOwnProperty("P_UserName")) {
						param.P_UserName = userInfo.UserName;
					}
					if (!param.hasOwnProperty("P_UserCode")) {
						param.P_UserCode = userInfo.UserCode;
					}
				};
				vm.$requestByUrl("/SQLData/QuerySql", param, function(data) {
					callBack(data);
				}, function(err) {
					console.log(err)
					layer.alert(JSON.stringify(err))
				});
				//vm.handleSizeChange(vm.paging.pageIndex);
			},
			newPost(sql, param, callBack) {
				let vm = this;
				param["sql"] = sql;
				if (vm.Request.getUserInfo()) {
					if (!param.hasOwnProperty("P_UserID")) {
						param.P_UserID = vm.Request.getUserInfo().UserID;
					}
					if (!param.hasOwnProperty("P_UserName")) {
						param.P_UserName = vm.Request.getUserInfo().UserName;
					}
					if (!param.hasOwnProperty("P_UserCode")) {
						param.P_UserCode = vm.Request.getUserInfo().UserCode;
					}
				}

				requestManager.requestByUrl("/SQLData/QuerySql", param, function(data) {
						callBack(data);
					},
					function(err) {

					});

			},
			TapPopup(data) { // 选中气泡项
				let vm = this;
				switch (data.name) {
					case '单据设置':
						//传递当前列给到列表和表头设置
						vm.$store.commit('ChangeAndSetStateData', {
							Name1: 'FormColumnSetting',
							data: vm.columns
						});

						uni.navigateTo({
							url: '/commonPage/Form/FieldSetting',
							events: {
								reloadPage: function(data) {
									vm.$refs.paging.refresh();
								}
							}
						})
						break;
					case '刷新':
						// 刷新页面
						vm.initConfig(vm.detailName);
						break;
					case '查阅审批流':
						ApprovalFun.viewListApprove(vm);

						break;
					default:
						break;
				}

			},
			async clickTabItem(data) { // 点击Tab栏
				let vm = this;
				let that = this;
				this.tabCurrent = data.index;

				if (data.title != '关联单据') {

					// 根据APP表单名称获取所属权限。
					// console.log(vm.TabList[data.index]['name']);
					// 根据当前选中的表单tab项，获取需要隐藏的权限。
					// await this.$store.dispatch('GetAPPRoleColFunByRoleID', {
					// 	moduleName: vm.TabList[data.index]['name'],
					// 	moduleType: 'formlist',
					// }).then(res => {
					// 	if (res.status == 200) {
					// 		vm.APPRoleColChildList = new Map(res.data.ds.map(row => [row.ColName, row]));
					// 	}
					// }).catch((err) => {
					// 	console.log(err)

					// })
					that.$request("getAPPRoleColFunByRoleID", {
						moduleName: vm.TabList[data.index]['name'],
						moduleType: 'formlist',
					}, (res) => {
						if (res.status == 200) {
							that.APPRoleColChildList = new Map();
							if (Array.isArray(res?.data?.ds)) {
								for (const row of res.data.ds) {
									if (row?.ColName !== undefined) {
										that.APPRoleColChildList.set(row.ColName, row);
									}
								}
							}
						};
					}, (err) => {
						console.log("getAPPRoleColFunByRoleID__" + JSON.stringify(err));
					})
				}
			},
			initConfig: function(objName) {
				let vm = this;
				var that = this;
				that.enabledSubmitBtn = false;

				// 获取主表字段权限
				/* await that.$store.dispatch('GetAPPRoleColFunByRoleID', {
					moduleName: that.detailName,
					moduleType: 'formdetail',
				}).then(res => {
					if (res.status == 200) {
						that.APPRoleCol = res.data.ds;
					};
				}).catch((err) => {
					console.log(err)
				}); */
				this.showMLoading = true;

				that.$requestByUrl('/AppFormDetail/GetDataByName', {
					objName: objName
				}, function(data) {
					that.globalData = that.$utils.deepClone(data);
					vm.physicalTableName = data.ds[0].physicalTableName;
					if (that.keyName && that.keyValue) {

						//显示通用审批流
						let comApprovalConfig =
							"select * from Ba_Audit where isnull(History,0)=0 and SourceTable='" +
							vm.physicalTableName + "' and SourceID=" + vm.keyValue + 'order by APFlowID desc';

						that.$requestByUrl("/SQLData/QuerySql", {
							sql: comApprovalConfig
						}, function(ret) {
							if (ret.ds.length > 0) {
								vm.isShowComApproval = true;

								vm.ApprovalID = ret.ds[0].APFlowID;

								vm.$request('WhetherItCanBeApproved', {
									P_TableName: vm.physicalTableName,
									P_PKValue: vm.keyValue
								}, function(data) {
									if (data.data.ds[0].ISSP == 1) {
										vm.isCurApproval = true;
										vm.ApprovalSort = data.data.ds[0].ApprovalSort;
									}
								})

							}
						})


						that.$requestByUrl("/SQLData/GetTableByKeyId", {
							physicalTableName: vm.physicalTableName,
							keyName: that.keyName,
							keyValue: that.keyValue
						}, function(ret) {

							if (ret.ds.length > 0) {
								let result = ret.ds[0];
								vm.formData = result;
								// console.log(result);
								let approvalConfig = {
									isEnableApproval: false
								}
								if (data.ds[0].hasOwnProperty('approvalConfig')) {
									approvalConfig = Object.assign(approvalConfig, JSON.parse(
										data.ds[
											0].approvalConfig))
								}
								vm.tableConfig({
									childFormList: JSON.parse(data.ds[0]
										.childFormsConfig),
									formDesign: JSON.parse(data.ds[0]
										.formDesignConfig),
									physicalTableName: data.ds[0].physicalTableName,
									workList: JSON.parse(data.ds[0].worksConfig),
									crudList: JSON.parse(data.ds[0].crudConfig),
									approvalConfig: approvalConfig
								});
							}
						}, function(err) {
							console.log(err)
						});
					}
				}, (err) => {
					console.log("initConfig__" + JSON.stringify(err));
				});
			},
			startApprove() { //判定是否启用审批流
				let vm = this;
				if (!vm.enabledSubmitBtn) {
					return;
				}
				vm.enabledSubmitBtn = false;
				ApprovalFun.startApprove(vm);
			},
			formApprove() { // 审批单据
				let vm = this;
				if (!vm.enabledSubmitBtn) {
					return;
				}
				vm.enabledSubmitBtn = false;
				ApprovalFun.formApprove(vm);
			},
			cancelApprove() { // 撤销审批
				let vm = this;
				if (!vm.enabledSubmitBtn) {
					return;
				}
				vm.enabledSubmitBtn = false;
				ApprovalFun.cancelApprove(vm);
			},
			tableConfig(options) {
				let vm = this;
				if (options.childFormList == null) {
					options.childFormList = [];
				}
				vm.workList = options.workList;
				vm.childFormList = options.childFormList;
				vm.approvalConfig = options.approvalConfig;


				// 调整业务按钮
				// 存在业务按钮时
				if (vm.workList.length) {
					// 从 Vuex 存储中获取无权限配置
					const permissionDeniedFunctions = this.$store.state.appConfigInfo.filterUnPermissionConfig;

					// 将业务按钮的条件进行eval执行
					const buttonConditions = this.btn_showCondition1(this.workList);

					// 提取所有无权限的函数名到一个 Set 中
					const funNamesSet = new Set(permissionDeniedFunctions.map(item => item.FunName));

					// 筛选按钮条件数组，只保留那些 name 不在无权限函数名集合中的元素
					const filteredButtons = buttonConditions.filter(item => !funNamesSet.has(item.name));

					// 映射数据并更新
					this.MoreSheetList = filteredButtons.map(item => ({
						...item,
						title: item.name
					}));

				};

				vm.TabList = [];
				for (let i = 0; i < vm.childFormList.length; i++) {
					//子表数据列表刷新
					// vm.childFormList[i].showListLoading = false;
					// vm.childFormList[i].finished = false;
					//增加子表页签
					vm.TabList.push(vm.childFormList[i]);
					vm.childPageInit(vm.childFormList[i]);
				}

				if (vm.TabList.length) {
					vm.clickTabItem({
						index: 0
					})
				};

				vm.TabList.push({
					title: '关联单据'
				});
				vm.link();
			},
			childPageInit(childObj) {
				let vm = this;
				var that = this;
				that.$requestByUrl('/AppFormList/GetDataByName', {
					objName: childObj.name
				}, function(data) {
					var filterCondition = data.ds[0]["filterCondition"];
					if (filterCondition == null) {
						filterCondition = "";
					}
					vm.childTableConfig({
						childObj: childObj,
						columns: JSON.parse(data.ds[0]["columnsConfig"]),
						params: {
							isFormList: data.ds[0]["isFormList"],
							physicalTableName: data.ds[0]["physicalTableName"],
							isPaging: data.ds[0]["isPaging"],
							filterCondition: filterCondition,
							defaultOrder: data.ds[0]["defaultOrder"],
							detailName: data.ds[0]["detailName"],
							isFormEdit: false,
							rowClassCol: data.ds[0]["rowClassCol"],
							onReadyCallBack: data.ds[0]["onReadyCallBack"],
							colClassCol: data.ds[0]["colClassCol"]
						}
					})
				}, (err) => {
					console.log("childPageInit__" + JSON.stringify(err));
				});

			},
			childTableConfig(options) {
				let vm = this;
				var that = this;
				options.childObj["tableData"] = [];
				options.childObj["columns"] = options.columns;
				var filterCondition = '1=1';
				if (options.params.filterCondition) {
					filterCondition += ' and ' + options.params.filterCondition;
				}
				let connectParams = vm.formData[options.childObj['connectParams']];
				if (!connectParams) {
					filterCondition += " and 1=0 ";
				} else {
					filterCondition += " and " + options.childObj['connectParams'] + "='" + connectParams +
						"'";
				}

				var titleCols = options.childObj.columns.filter(function(item) {
					return item.isTitle == true
				});
				if (titleCols.length > 0) {
					options.childObj["titleCol"] = titleCols[0];
				}

				vm.$requestByUrl('/SQLData/GetDataByPhysicalTableNameByQueryPaging_Uniapp', {
					tableName: options.params.physicalTableName,
					columnsStr: JSON.stringify([]),
					currentCol: '',
					pageIndex: 1,
					pageSize: 9999,
					isForm: (options.params.isFormList || true).toString(),
					filterCondition: filterCondition,
					defaultOrder: options.params.defaultOrder || ''
				}, function(data) {
					var tableData = data.ds;
					// console.log(titleCols);
					// console.log(tableData);
					let filterData = options.childObj.columns.filter(item => {
						return item.colName.indexOf("FilePath") !== -1
					})
					// console.log(filterData);
					if (filterData.length) {
						function startsWithHttp(url) {
							return url.startsWith('http://') || url.startsWith('https://');
						}
						// 处理文件上传字段操作
						filterData.forEach(item => {
							data.ds.forEach(rowItem => {
								let arrData = [];
								if (!vm.$utils.isEmpty(rowItem[item.colName])) {
									let splitData = rowItem[item.colName].split(',');
									// console.log(splitData);
									arrData = splitData.map((item, index, originalArray) => {

										let mapItem = item;
										if (!startsWithHttp(item)) {
											mapItem = vm.Request.IPAgreement() + vm.Request
												.serverIP() + item;
										}

										return {
											path: mapItem
										};
									});
								};
								// 增加 _show 字段存储数组数据
								rowItem[item.colName + '_show'] = arrData;
							})
						})

					}
					// FilePath
					// data.ds.map(item => {
					// 	item
					// })
					// console.log(data.ds);
					Vue.set(options.childObj, 'tableData', data.ds);

					// options.childObj["tableData"] = data.ds;


					vm.refreshChildCol(options.childObj);
					vm.$forceUpdate();
					// //}
					// // if (curChildObj.pageIndex == 1) {

					// // } else {
					// //     curChildObj.tableData = curChildObj.tableData.concat(data.ds);
					// // }

					// for (var i = 0; i < curChildObj.tableData.length; i++) {
					// 	curChildObj.tableData[i].objNo = (i + 1).toString();
					// 	if (!curChildObj.tableData[i].guid) {
					// 		curChildObj.tableData[i].guid = vm.guid();
					// 	}
					// }
					// if (data.ds1.length > 0) {
					// 	//绑定总长度
					// 	if (curChildObj.tableData.length >= parseInt(data.ds1[0]["@TotalCount"])) {
					// 		curChildObj.finished = true;
					// 	}
					// }
					// curChildObj.pageIndex = curChildObj.pageIndex + 1;
					// // for(var i=0;i<tableData.length;i++){
					// //   tableData[i].objNo = (i+1).toString();
					// // }
					// //
					// // vm.$set(curChildObj, "tableData",tableData );
					// vm.refreshChildCol(curChildObj);
					// vm.calSummaryData(curChildObj);

				}, (err) => {
					console.log("childPageInit__" + JSON.stringify(err));
					vm.tableData = [];
				});
			},
			// async refreshChildCol(childObjs) {
			// 	let childObj = this.$utils.deepClone(childObjs)

			// 	const promises = childObj.columns.map(async (column) => {
			// 		if (column.colType == 2) {
			// 			const selDetailObj = column.selDetail;

			// 			if (selDetailObj.type < 3) {
			// 				const sql = selDetailObj.dataSource;
			// 				const data = await vm.changeDataAjax(sql, "1=1");
			// 				selDetailObj.sqlDataSource =
			// 					data;
			// 			} else if (selDetailObj.type === 3) {
			// 				const valueList = [];

			// 				for (const row of childObj.tableData) {
			// 					const values = row[column.colName];
			// 					if (values) {
			// 						valueList.push(...values.toString().split(',').map(value =>
			// 							`'${value}'`));
			// 					}
			// 				}

			// 				if (valueList.length > 0) {
			// 					const data = await vm.changeDataAjax(
			// 						selDetailObj.dataSource,
			// 						`${selDetailObj.hiddenValue} IN (${valueList.join(',')})`
			// 					);
			// 					selDetailObj.sqlDataSource = data;
			// 				} else {
			// 					selDetailObj.sqlDataSource = [];
			// 				}
			// 			}
			// 		}
			// 	});

			// 	await Promise.all(promises);

			// 	await vm.calSummary(childObj);
			// 	vm.$forceUpdate();
			// },
			refreshChildCol(childObj) {
				let vm = this;
				let that = this;
				childObj.columns.forEach(item => {
					if (item.colType == 2 && item.selDetail.type < 3) {
						let sql = item.selDetail.dataSource;
						let selDetailObj = item.selDetail;
						that.changeDataAjax(sql, "1=1", function(data, requestObj) {
							requestObj['sqlDataSource'] = data;
							that.$forceUpdate();
						}, selDetailObj);
					} else if (item.colType == 2 && item.selDetail.type == 3) {
						let valueList = [];

						childObj.tableData.forEach(row => {
							if (!vm.$utils.isEmpty(row[item.colName])) {
								let kData = row[item.colName].toString().split(',');


								kData.forEach((kItem, kIndex) => {
									valueList.push("'" + row[item.colName].toString()
										.split(',')[
											kIndex] + "'");
								})
							}
						});

						if (valueList.length > 0) {
							let selDetailObj = item.selDetail;
							that.changeDataAjax(item.selDetail.dataSource, item.selDetail.hiddenValue +
								" in (" +
								valueList.join(',') + ") ",
								function(data, requestObj) {
									requestObj['sqlDataSource'] = data;
									that.$forceUpdate();
								}, selDetailObj);
						} else {
							item.selDetail.sqlDataSource = [];
						}

					}
				})


				// for (var i = 0; i < childObj.columns.length; i++) {
				// 	//下拉框数据加载
				// 	if (childObj.columns[i].colType == 2 && childObj.columns[i].selDetail.type < 3) {
				// 		var sql = childObj.columns[i].selDetail.dataSource;
				// 		var selDetailObj = childObj.columns[i].selDetail;
				// 		vm.changeDataAjax(sql, "1=1", function(data, requestObj) {
				// 			requestObj['sqlDataSource'] = data;
				// 			vm.$forceUpdate();
				// 		}, selDetailObj);
				// 	} else if (childObj.columns[i].colType == 2 && childObj.columns[i].selDetail.type == 3) {
				// 		var valueList = [];
				// 		for (var j = 0; j < childObj.tableData.length; j++) {
				// 			//if (vm.tableData[j][vm.columns[i].selDetail.hiddenValue] != null && vm.tableData[j][vm.columns[i].selDetail.hiddenValue] != undefined && vm.tableData[j][vm.columns[i].selDetail.hiddenValue] != '') {
				// 			//    valueList.push("'" + vm.tableData[j][vm.columns[i].selDetail.hiddenValue] + "'");
				// 			//}
				// 			if (childObj.tableData[j][childObj.columns[i].colName]) {
				// 				for (var k = 0; k < childObj.tableData[j][childObj.columns[i].colName].toString().split(
				// 						',').length; k++) {
				// 					valueList.push("'" + childObj.tableData[j][childObj.columns[i].colName].toString()
				// 						.split(',')[k] + "'");
				// 				}
				// 			}
				// 		}
				// 		//var sql = "select * from (" + vm.columns[i].selDetail.dataSource + ")t";
				// 		if (valueList.length > 0) {
				// 			var selDetailObj = childObj.columns[i].selDetail;
				// 			vm.changeDataAjax(childObj.columns[i].selDetail.dataSource, childObj.columns[i]
				// 				.selDetail.hiddenValue + " in (" + valueList.join(',') + ") ",
				// 				function(data, requestObj) {
				// 					requestObj.sqlDataSource = data;
				// 					console.log(requestObj);
				// 					console.log(childObj)
				// 					vm.$forceUpdate();
				// 				}, selDetailObj);
				// 		} else {
				// 			childObj.columns[i].selDetail.sqlDataSource = [];
				// 		}
				// 	}
				// }


				vm.calSummary(childObj);
				vm.$forceUpdate();
			},
			FileTypeByName(data, col) {
				// console.log(data);

				let pathData = data[col.colName].split(',');
				// console.log(pathData);
				// return pathData;


				let FileTypeBack = this.$utils.isFileType(data[col.colName]);
				let pathIcon = '';
				let path = '/static/assets/image/img/';
				let pathUrl = '';
				switch (FileTypeBack) {
					case 'image':
						pathIcon = 'image';
						break;
					case 'video':
						pathIcon = 'video';
						break;
					case 'text':
						pathIcon = 'text';
						break;
					case 'pdf':
						pathIcon = 'pdf';
						break;
					case 'spreadsheet':
						pathIcon = 'xls';
						break;
					default:
						break;
				};
				if (this.$utils.isEmpty(pathIcon)) return '';
				pathUrl = path + pathIcon + '.png';
				return pathUrl;
			},
			btnShowCallBack(data, col) { // 临时--判断是否是文件
				let FileTypeBack = this.$utils.isFileType(data[col.colName]);
				let BtnBoolean = false;
				switch (FileTypeBack) {
					case false:
					case 'unknown':
						BtnBoolean = false;
						break;
					default:
						BtnBoolean = true
						break;
				};
				return BtnBoolean;
			},
			FilePathView(data, col) { // 预览文件
				console.log(data);
				let FileTypeBack = this.$utils.isFileType(data[col.colName]);
				switch (FileTypeBack) {
					case 'video':
						uni.navigateTo({
							url: '/commonPage/Form/video-preview' + '?url=' + this.processImageUrl(data[col
								.colName])
						})
						break;
					case 'image':
						// 查看图片
						uni.previewImage({
							current: 0,
							urls: [this.processImageUrl(data[col.colName])],
							success() {},
							fail(err) {
								console.log(err);
							}
						})
						break;
					default:
						// 预览文件
						uni.downloadFile({
							url: this.processImageUrl(data[col.colName]),
							success: function(res) {
								var filePath = plus.io.convertLocalFileSystemURL(res.tempFilePath);
								console.log(JSON.stringify(filePath))
								open.openFile({
									filename: filePath,
									title: "预览文件",
									isShowBackIcon: true
								}, ret => {

									console.log(JSON.stringify(ret))
								})
							}
						})
						break;
				};
			},
			processImageUrl(url) { // 处理图片链接地址
				if (uni.$m.utils.isEmpty(url)) '';
				url = url.trim();

				function urlRegular(value) {
					return /^((https|http|ftp|rtsp|mms):\/\/)/
						.test(value)
				}

				let isHttp = urlRegular(url);
				if (isHttp) {
					return url;
				} else {
					return this.Request.IPAgreement() + this.Request.serverIP() + url;
				}

			},
			//显示下拉数据源中的真实数据
			showActualValue(value, colObject, originValue) {
				let vm = this;
				// console.log(colObject)
				// console.log(colObject.selDetail.sqlDataSource)
				if (colObject.selDetail.sqlDataSource) {
					var curObject = colObject.selDetail.sqlDataSource.filter(function(item) {
						return item[colObject.selDetail.hiddenValue] == value
					});
					if (curObject.length > 0) {
						return curObject[0][colObject.selDetail.displayValue];
					} else if (originValue) {
						return originValue;
					} else {
						return '';
					}
				} else {
					return '';
				}
				//return '';
			},
			parseQueryString(queryString) {
				let vm = this;
				// 如果queryString不包含"?"，则默认整个字符串为URL部分  
				const [url, queryStringPart] = queryString.split('?');

				// 如果没有查询字符串部分，直接返回包含URL的结果  
				if (!queryStringPart) {
					return {
						Url: url.replace(/\.vue$/, '')
					};
				}

				let params = queryStringPart.split('&').reduce((acc, current) => {
					let [key, value] = current.split('=');
					acc[key] = value;
					return acc;
				}, {});

				params['Url'] = url.replace(/\.vue$/, '');;
				return params
			},
			openDetailPage(data) { // 点击前往关联单据
				let vm = this;
				console.log(data);
				if (this.$utils.isEmpty(data.APPUrl)) {
					return
				}

				let menu = this.$utils.deepClone(data);


				let menuData = this.parseQueryString(menu.APPUrl);


				var returnData = {
					detailTitle: menuData['objName'],
					detailName: menuData['objName'],
					keyName: menuData['keyName'],
					keyValue: menuData['keyValue'],
					dataInfo: {}
				}
				vm.$store.commit('ChangeAndSetStateData', {
					Name1: 'MenuDetail',
					data: this.$utils.deepClone(returnData)
				});


				uni.navigateTo({
					url: menuData['Url']
				})

				// if (menu['src']) {
				// 	menu['Para'] = menu['src'].split('=')[1]
				// } else {
				// 	this.$utils.msg('未配置关联单据路径')
				// 	return
				// }

				// menu['APFunName'] = menu['title'];
				// console.log(menu)

				// this.$store.commit('ChangeAndSetStateData', {
				// 	Name1: 'Menu',
				// 	data: menu
				// });

				// uni.navigateTo({
				// 	url: '/commonPage/Form/Edit',
				// 	fail(err) {
				// 		console.log(err)
				// 	}
				// })

			},
			link() {
				let vm = this;
				let that = this;
				//查询关联单据

				this.$request('getAppRelatedDocuments', {
					objName: that.detailName,
					KeyID: that.formData[that.keyName],
				}, (ret) => {
					if (ret.status == 200) {
						that.objDetailModelList = ret.data.ds;
					}
				}, (err) => {
					console.log("link__" + JSON.stringify(err))
				})


				// vm.post("select * from paramlink where paramName=@paramName order by sort asc ", {
				// 	paramName: this.keyName
				// }, function(data) {
				// 	// console.log(data)
				// 	if (data.ds.length) {
				// 		vm.objDetailModelList = data.ds;
				// 	}
				// })

				// 			var objName = $("#keyName").val();
				// 			var objValue = $("#keyValue").val();
				// 			vm.post("select * from paramlink where paramName=@paramName order by sort asc ", {
				// 				paramName: objName
				// 			}, function (data) {
				// 				vm.objDetailModelList = [];
				// 				for (var i = 0; i < F.ui.contextMenuTab.items.length; i++) {
				// 					F.ui.contextMenuTab.removeTab(i);
				// 				}
				// 				for (var i = 0; i < data.ds.length; i++) {
				// 					if (data.ds[i].tabType == 1) {
				// 						var searchKeyName = data.ds[i].keyName;
				// 						var searchKeyValue = 0;
				// 						//查询主键值
				// 						vm.post("select * from " + data.ds[i].tableName + " where " + objName + "='" + objValue + "'  ", {}, function (ret) {
				// 							if (ret.ds.length > 0) {
				// 								var src = data.ds[i].src + "&keyName=" + searchKeyName + "&keyValue=" + ret.ds[0][searchKeyName] + "&isView=1";
				// 								//data.ds[i].src = src;
				// 								//parent.vm.objDetailModelList.push(data.ds[i]);
				// 								var isActive = false;
				// 								if (i == 0) {
				// 									isActive = true;
				// 								}
				// 								//添加页签
				// 								F.ui.contextMenuTab.addTab({
				// 									title: data.ds[i].title,
				// 									iframe: true,
				// 									iframeUrl: src
				// 								}, false, isActive);
				// 							}
				// 						});
				// 					}
				// 					else if (data.ds[i].tabType == 2) {
				// 						var query = objName + "='" + objValue + "'";
				// 						let base64Helper = Base64;
				// 						query = base64Helper.encode(query)
				// 						var src = data.ds[i].src + "&query=" + query + "&isView=1";
				// 						//data.ds[i].src = src;
				// 						//parent.vm.objDetailModelList.push(data.ds[i]);
				// 						var isActive = false;
				// 						if (i == 0) {
				// 							isActive = true;
				// 						}
				// 						//添加页签
				// 						F.ui.contextMenuTab.addTab({
				// 							title: data.ds[i].title,
				// 							iframe: true,
				// 							iframeUrl: src
				// 						}, false, isActive);
				// 					}
				// 					else if (data.ds[i].tabType == 3) {
				// 						var src = data.ds[i].src + "&" + objName + "=" + objValue;
				// 						var isActive = false;
				// 						if (i == 0) {
				// 							isActive = true;
				// 						}
				// 						//添加页签
				// 						F.ui.contextMenuTab.addTab({
				// 							title: data.ds[i].title,
				// 							iframe: true,
				// 							iframeUrl: src
				// 						}, false, isActive);



				// 					}
				// 				}
				// 			});
				// 			F.ui.windowContextMenu.show();
				// 			F.ui.windowContextMenu.maximize();
				// 			F.ui.windowContextMenu.setTitle(vm.showDetailTitle);

			},
			//计算汇总数据
			calSummary(childObj) {
				let vm = this;
				var totalFunctions = childObj.columns.filter(function(item) {
					return item.colTotalFunction;
				});
				childObj["totalFunctions"] = totalFunctions;
				totalFunctions.forEach(function(item) {
					if (item.colTotalFunction == "sum") {
						//保留位数
						var fixNum = 2;
						var totalNum = 0;
						for (var j = 0; j < childObj.tableData.length; j++) {
							var currentNum = parseFloat(childObj.tableData[j][item.colName]);
							if (isNaN(currentNum)) {
								currentNum = 0;
							}
							totalNum += currentNum;
						}
						item["summaryData"] = totalNum.toFixed(fixNum);
					}
				});
				vm.$forceUpdate();
			},
			showChildFormTableDataLen(tableData) {
				let vm = this;
				//console.log(tableData.length)
				// return tableData.length.toString();
				var that = this;
				if (that.childFormList.length > 0 && that.childFormList[0].tableData) {
					return that.childFormList[0].tableData.length;
				} else {
					return '';
				}

			},
			async selfWorkHandler(work) { // 点击底栏自定义按钮
				let vm = this;
				let that = this;
				if (!vm.enabledSubmitBtn) {
					return;
				}

				function task1() {
					return new Promise((resolve, reject) => {
						try {

							var script = work.script.replace(/\['/g, "vm.formData['");
							script = script.replace(/\["/g, "vm.formData[\"");
							eval(script);


							resolve();

						} catch (error) {
							reject(error);
						}
					});
				}

				task1().then(() => {
					vm.enabledSubmitBtn = true;
					vm.$utils.hideLoading();
				}).catch((error) => {
					vm.enabledSubmitBtn = true;
					vm.$utils.hideLoading();
					uni.showToast({
						title: error,
						icon: 'error'
					})
					console.error('An error occurred:', error);
				});
			},
			//按钮显示条件判断
			btn_showCondition(type, btn) {
				let vm = this;
				try {
					var _this = this;
					var result = true;
					var showScript = "";

					//普通crud
					if (type == 1) {
						if (btn == "新增") {
							showScript = _this.crudList[0].show;
						} else if (btn == "编辑") {
							showScript = _this.crudList[1].show;
						} else if (btn == "删除") {
							showScript = _this.crudList[2].show;
						}
					}
					//业务按钮
					else if (type == 2) {
						showScript = btn.show;
					}
					//调入按钮
					else if (type == 3) {
						showScript = btn.btnShow;
					}
					if (showScript) {
						var script = showScript.replace(/\['/g, "_this.formData['");
						script = script.replace(/\["/g, "_this.formData[\"");
						eval("result=(" + script + ")");
					}
					return result;
				} catch (e) {
					return false;
				}
			},
			btn_showCondition1(data) { // 映射业务按钮数组显示
				let vm = this;
				var _this = this;
				let newdata = [];
				try {

					if (data.length) {
						newdata = data.filter(btn => {
							var showScript = btn.show;
							var script = showScript.replace(/\['/g, "_this.formData['");
							script = script.replace(/\["/g, "_this.formData[\"");
							if (_this.$utils.isEmpty(script)) {
								return true
							} else {
								return eval("(" + script + ")");
							}
						});
					}
					return newdata;
				} catch (e) {
					return newdata;
				}

			},
			openMoreSheet() { // 点击更多按钮 --- 业务按钮
				let vm = this;
				let that = this;
				if (!vm.enabledSubmitBtn) {
					return;
				}

				plus.nativeUI.actionSheet({
					cancel: "取消",
					buttons: this.MoreSheetList
				}, function(event) {
					let {
						index
					} = event;

					// console.log(index);
					if (index > 0) {
						// console.log(that.MoreSheetList[index - 1]);
						that.selfWorkHandler(that.MoreSheetList[index - 1]);
					} else {
						vm.enabledSubmitBtn = true;
					}
				});

				// this.MoreSheetList = JSON.parse(JSON.stringify(this.btn_showCondition1(this.workList)));
				// console.log(this.MoreSheetList);

				// this.showMoreSheet = true;
			},
			closeSheetBtn() {
				this.showMoreSheet = false;
			},
			//进入编辑区域
			toEdit() {
				let vm = this;

				if (!vm.enabledSubmitBtn) {
					return;
				}

				vm.$store.commit('ChangeAndSetStateData', {
					Name1: 'MenuDetail',
					data: this.$utils.deepClone(vm.MenuDetail)
				});

				uni.navigateTo({
					url: '/commonPage/Form/Edit'
				})
			},
			/*系统函数结束*/
			/*change获取数据机制处理
			  用于change过程中反复调用后台处理的机制问题
			*/
			changeDataAjax: function(datasource, query, callBack, requestObj) {
				let vm = this;
				var dsResult = vm.changeDataSource.filter(function(item) {
					return item.datasource == datasource && item.query == query;
				});
				if (dsResult.length == 0) {
					var returnData = [];
					var sql = "select * from (" + datasource + ")t";
					sql += " where " + query;

					//dataSource处理下
					//带有@@父节点标识的字段
					if (sql.indexOf('@') >= 0) {
						for (var name in vm.formData) {
							var repalceValue = "'" + vm.formData[name] + "'";
							eval("sql = sql.replace(/@" + name + "/g, repalceValue)");
						}
					}
					// let rowObj = this.$utils.deepClone(this.editFrame);
					// console.log(rowObj);
					// if (sql.indexOf('@') >= 0) {
					// 	for (let name in rowObj) {
					// 		let repalceValue = "'" + rowObj[name] + "'";
					// 		eval("sql = sql.replace(/@" + name + "/g, repalceValue)");
					// 	}
					// }
					vm.$requestByUrl('/SQLData/GetDataBySql', {
						sql: sql
					}, (data) => {
						// if (data.status == 200) {
						returnData = data.ds;

						vm.changeDataSource.push({
							datasource: datasource,
							query: query,
							data: returnData
						});
						callBack(returnData, requestObj);
						// }
					}, (err) => {
						console.log("changeDataAjax__" + JSON.stringify(err));
						// layer.alert("【sql】", {
						// 	title: sql,
						// })
					});

					// var ajaxRequest = vm.Request.PromiseRequestByUrl('/SQLData/GetDataBySql', {
					// 	sql: sql
					// });

					// ajaxRequest.promise.then(function(data) {
					// 	if (data.status == 200) {
					// 		returnData = data.data.ds;
					// 		vm.changeDataSource.push({
					// 			datasource: datasource,
					// 			query: query,
					// 			data: returnData
					// 		});
					// 		callBack(returnData, requestObj);
					// 	}
					// });
				} else {
					callBack(dsResult[0].data, requestObj);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	* {
		box-sizing: border-box;
	}

	.van-badge {
		margin: 0px 5px;
		background-color: #51d0d0;
		color: #fff;
		display: block;
		min-width: 25px;
		height: 25px;
		line-height: 25px;
		// padding: 3px;
		float: left;
		vertical-align: middle;
		border-radius: 8px;
		text-align: center;
	}

	.content {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #f9f9f9;


		.content_main {
			flex: 1;
			overflow: auto;
			position: relative;


			.TopCard {
				background-color: #4499ec;

				.CardInfo {
					flex: 3;
				}

				.CardTag {
					position: absolute;
					right: 20px;
					top: 25rpx;

				}
			}
		}
	}

	.content_bottom1 {
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		height: 70px;
		line-height: 70px;
		padding: 6px 15px;
		// border-top: 1px solid #efefef;
		box-shadow: 1px 0 12px -9px #333;
		z-index: 99;

		.workBtn {
			border-color: #ddd !important;
			margin-left: 10px !important;

			&.small-font {
				font-size: 12px !important;
			}

			&:not(.small-font) {
				font-size: 14px;
			}
		}
	}
</style>